package com.easywan.web.controller.image;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.easywan.core.BaseController;
import com.easywan.vo.Hearthstone;
/**
 * 
 * @author tangkang
 *
 */
@Controller
@RequestMapping("image/hearthstone")
public class HearthstoneController extends BaseController{
	@RequestMapping("index")
	public String index(){
		return toPath("image/hearthstone/index.jsp");
	}
	@RequestMapping("getCard")
	public void getCard(HttpServletRequest request,HttpServletResponse response){
		Integer carType = getInt(request, "carType");
		Integer prefission = getInt(request, "prefission");
		String name = getString(request, "name");
		String race = getString(request, "race");
		String desc = getString(request,"desc");
		Integer magic = getInt(request, "magic");
		Integer hit = getInt(request, "hit");
		Integer health = getInt(request, "health");
		Integer power = getInt(request, "power");
		
		Hearthstone stone = new Hearthstone();
		stone.setCarType(carType);
		
		BufferedImage bi = stone.creater(carType,
				stone.getCarFrame(prefission),
				stone.getMagic(magic),
				 null, stone.getCarType(power), 
				 null, stone.getHit(hit),
				 stone.getHealth(health), null, name);
		//byte[] buffer = DubboUtils.toBytes(bi);
	
      //5、图形写给浏览器  
        response.setContentType("image/jpeg");  
        //发头控制浏览器不要缓存  
        response.setDateHeader("expries", -1);  
        response.setHeader("Cache-Control", "no-cache");  
        response.setHeader("Pragma", "no-cache"); 
		//response.getWriter();
        try {
			ImageIO.write(bi, "png", response.getOutputStream());
		} catch (IOException e) {
			e.printStackTrace();
		}  
	}
}
